home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / os2 / daytime.zip / getdate.c < prev    next >
C/C++ Source or Header  |  1995-08-20  |  51KB  |  1,942 lines

  1.  
  2. /*  A Bison parser, made from getdate.y with Bison version GNU Bison version 1.22
  3.   */
  4.  
  5. #define YYBISON 1  /* Identify Bison output.  */
  6.  
  7. #define    tAGO    258
  8. #define    tDAY    259
  9. #define    tDAYZONE    260
  10. #define    tID    261
  11. #define    tMERIDIAN    262
  12. #define    tMINUTE_UNIT    263
  13. #define    tMONTH    264
  14. #define    tMONTH_UNIT    265
  15. #define    tSEC_UNIT    266
  16. #define    tSNUMBER    267
  17. #define    tUNUMBER    268
  18. #define    tZONE    269
  19. #define    tDST    270
  20.  
  21. #line 1 "getdate.y"
  22.  
  23. /*
  24. **  Originally written by Steven M. Bellovin <smb@research.att.com> while
  25. **  at the University of North Carolina at Chapel Hill.  Later tweaked by
  26. **  a couple of people on Usenet.  Completely overhauled by Rich $alz
  27. **  <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
  28. **  send any email to Rich.
  29. **
  30. **  This grammar has nine shift/reduce conflicts.
  31. **
  32. **  This code is in the public domain and has no copyright.
  33. */
  34. /* SUPPRESS 287 on yaccpar_sccsid *//* Unusd static variable */
  35. /* SUPPRESS 288 on yyerrlab *//* Label unused */
  36.  
  37. #ifdef HAVE_CONFIG_H
  38. #if defined (emacs) || defined (CONFIG_BROKETS)
  39. #include <config.h>
  40. #else
  41. #include "config.h"
  42. #endif
  43. #endif
  44.  
  45. /* Since the code of getdate.y is not included in the Emacs executable
  46.    itself, there is no need to #define static in this file.  Even if
  47.    the code were included in the Emacs executable, it probably
  48.    wouldn't do any harm to #undef it here; this will only cause
  49.    problems if we try to write to a static variable, which I don't
  50.    think this code needs to do.  */
  51. #ifdef emacs
  52. #undef static
  53. #endif
  54.  
  55. /* The following block of alloca-related preprocessor directives is here
  56.    solely to allow compilation by non GNU-C compilers of the C parser
  57.    produced from this file by old versions of bison.  Newer versions of
  58.    bison include a block similar to this one in bison.simple.  */
  59.    
  60. #ifdef __GNUC__
  61. #define alloca __builtin_alloca
  62. #else
  63. #ifdef HAVE_ALLOCA_H
  64. #include <alloca.h>
  65. #else
  66. #ifdef _AIX
  67.  #pragma alloca
  68. #else
  69. void *alloca ();
  70. #endif
  71. #endif
  72. #endif
  73.  
  74. #ifdef __GNUC__
  75. #undef alloca
  76. #define alloca __builtin_alloca
  77. #else
  78. #ifdef HAVE_ALLOCA_H
  79. #include <alloca.h>
  80. #else
  81. #ifdef _AIX /* for Bison */
  82.  #pragma alloca
  83. #else
  84. void *alloca ();
  85. #endif
  86. #endif
  87. #endif
  88.  
  89. #ifdef __IBMC__
  90. #include <malloc.h>
  91. #endif
  92.  
  93. #include <stdio.h>
  94. #include <ctype.h>
  95. #include <stdlib.h>
  96. #include <string.h>
  97.  
  98. /* The code at the top of get_date which figures out the offset of the
  99.    current time zone checks various CPP symbols to see if special
  100.    tricks are need, but defaults to using the gettimeofday system call.
  101.    Include <sys/time.h> if that will be used.  */
  102.  
  103. #if    defined(vms)
  104.  
  105. #include <types.h>
  106. #include <time.h>
  107.  
  108. #else
  109.  
  110. #include <sys/types.h>
  111.  
  112. #ifdef TIME_WITH_SYS_TIME
  113. #include <sys/time.h>
  114. #include <time.h>
  115. #else
  116. #ifdef HAVE_SYS_TIME_H
  117. #include <sys/time.h>
  118. #else
  119. #include <time.h>
  120. #endif
  121. #endif
  122.  
  123. #ifdef timezone
  124. #undef timezone /* needed for sgi */
  125. #endif
  126.  
  127. #if defined(HAVE_SYS_TIMEB_H)
  128. #include <sys/timeb.h>
  129. #else
  130. /*
  131. ** We use the obsolete `struct timeb' as part of our interface!
  132. ** Since the system doesn't have it, we define it here;
  133. ** our callers must do likewise.
  134. */
  135. struct timeb {
  136.     time_t        time;        /* Seconds since the epoch    */
  137.     unsigned short    millitm;    /* Field not used        */
  138.     short        timezone;    /* Minutes west of GMT        */
  139.     short        dstflag;    /* Field not used        */
  140. };
  141. #endif /* defined(HAVE_SYS_TIMEB_H) */
  142.  
  143. #endif    /* defined(vms) */
  144.  
  145. #if defined (STDC_HEADERS) || defined (USG)
  146. #include <string.h>
  147. #endif
  148.  
  149. /* Some old versions of bison generate parsers that use bcopy.
  150.    That loses on systems that don't provide the function, so we have
  151.    to redefine it here.  */
  152. #if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
  153. #define bcopy(from, to, len) memcpy ((to), (from), (len))
  154. #endif
  155.  
  156. extern struct tm    *gmtime();
  157. extern struct tm    *localtime();
  158.  
  159. #define yyparse getdate_yyparse
  160. #define yylex getdate_yylex
  161. #define yyerror getdate_yyerror
  162.  
  163. static int yylex ();
  164. static int yyerror ();
  165.  
  166. #if    !defined(lint) && !defined(SABER)
  167. static char RCS[] =
  168.     "$Header: str2date.y,v 2.1 90/09/06 08:15:06 cronan Exp $";
  169. #endif    /* !defined(lint) && !defined(SABER) */
  170.  
  171.  
  172. #define EPOCH        1970
  173. #define HOUR(x)        ((time_t)(x) * 60)
  174. #define SECSPERDAY    (24L * 60L * 60L)
  175.  
  176.  
  177. /*
  178. **  An entry in the lexical lookup table.
  179. */
  180. typedef struct _TABLE {
  181.     char    *name;
  182.     int        type;
  183.     time_t    value;
  184. } TABLE;
  185.  
  186.  
  187. /*
  188. **  Daylight-savings mode:  on, off, or not yet known.
  189. */
  190. typedef enum _DSTMODE {
  191.     DSTon, DSToff, DSTmaybe
  192. } DSTMODE;
  193.  
  194. /*
  195. **  Meridian:  am, pm, or 24-hour style.
  196. */
  197. typedef enum _MERIDIAN {
  198.     MERam, MERpm, MER24
  199. } MERIDIAN;
  200.  
  201.  
  202. /*
  203. **  Global variables.  We could get rid of most of these by using a good
  204. **  union as the yacc stack.  (This routine was originally written before
  205. **  yacc had the %union construct.)  Maybe someday; right now we only use
  206. **  the %union very rarely.
  207. */
  208. static char    *yyInput;
  209. static DSTMODE    yyDSTmode;
  210. static time_t    yyDayOrdinal;
  211. static time_t    yyDayNumber;
  212. static int    yyHaveDate;
  213. static int    yyHaveDay;
  214. static int    yyHaveRel;
  215. static int    yyHaveTime;
  216. static int    yyHaveZone;
  217. static time_t    yyTimezone;
  218. static time_t    yyDay;
  219. static time_t    yyHour;
  220. static time_t    yyMinutes;
  221. static time_t    yyMonth;
  222. static time_t    yySeconds;
  223. static time_t    yyYear;
  224. static MERIDIAN    yyMeridian;
  225. static time_t    yyRelMonth;
  226. static time_t    yyRelSeconds;
  227.  
  228.  
  229. #line 209 "getdate.y"
  230. typedef union {
  231.     time_t        Number;
  232.     enum _MERIDIAN    Meridian;
  233. } YYSTYPE;
  234.  
  235. #ifndef YYLTYPE
  236. typedef
  237.   struct yyltype
  238.     {
  239.       int timestamp;
  240.       int first_line;
  241.       int first_column;
  242.       int last_line;
  243.       int last_column;
  244.       char *text;
  245.    }
  246.   yyltype;
  247.  
  248. #define YYLTYPE yyltype
  249. #endif
  250.  
  251. #include <stdio.h>
  252.  
  253. #ifndef __cplusplus
  254. #ifndef __STDC__
  255. #define const
  256. #endif
  257. #endif
  258.  
  259.  
  260.  
  261. #define    YYFINAL        51
  262. #define    YYFLAG        -32768
  263. #define    YYNTBASE    19
  264.  
  265. #define YYTRANSLATE(x) ((unsigned)(x) <= 270 ? yytranslate[x] : 29)
  266.  
  267. static const char yytranslate[] = {     0,
  268.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  269.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  270.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  271.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  272.      2,     2,     2,    17,     2,     2,    18,     2,     2,     2,
  273.      2,     2,     2,     2,     2,     2,     2,    16,     2,     2,
  274.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  275.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  276.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  277.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  278.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  279.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  280.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  281.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  282.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  283.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  284.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  285.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  286.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  287.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  288.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  289.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  290.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  291.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  292.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  293.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  294.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15
  295. };
  296.  
  297. #if YYDEBUG != 0
  298. static const short yyprhs[] = {     0,
  299.      0,     1,     4,     6,     8,    10,    12,    14,    16,    19,
  300.     24,    29,    36,    43,    45,    47,    50,    52,    55,    58,
  301.     62,    68,    72,    75,    80,    83,    87,    90,    92,    95,
  302.     98,   100,   103,   106,   108,   111,   114,   116,   118,   119
  303. };
  304.  
  305. static const short yyrhs[] = {    -1,
  306.     19,    20,     0,    21,     0,    22,     0,    24,     0,    23,
  307.      0,    25,     0,    27,     0,    13,     7,     0,    13,    16,
  308.     13,    28,     0,    13,    16,    13,    12,     0,    13,    16,
  309.     13,    16,    13,    28,     0,    13,    16,    13,    16,    13,
  310.     12,     0,    14,     0,     5,     0,    14,    15,     0,     4,
  311.      0,     4,    17,     0,    13,     4,     0,    13,    18,    13,
  312.      0,    13,    18,    13,    18,    13,     0,    13,    12,    12,
  313.      0,     9,    13,     0,     9,    13,    17,    13,     0,    13,
  314.      9,     0,    13,     9,    13,     0,    26,     3,     0,    26,
  315.      0,    13,     8,     0,    12,     8,     0,     8,     0,    12,
  316.     11,     0,    13,    11,     0,    11,     0,    12,    10,     0,
  317.     13,    10,     0,    10,     0,    13,     0,     0,     7,     0
  318. };
  319.  
  320. #endif
  321.  
  322. #if YYDEBUG != 0
  323. static const short yyrline[] = { 0,
  324.    223,   224,   227,   230,   233,   236,   239,   242,   245,   251,
  325.    257,   264,   270,   280,   284,   288,   295,   299,   303,   309,
  326.    313,   318,   324,   328,   333,   337,   344,   348,   351,   354,
  327.    357,   360,   363,   366,   369,   372,   375,   380,   408,   411
  328. };
  329.  
  330. static const char * const yytname[] = {   "$","error","$illegal.","tAGO","tDAY",
  331. "tDAYZONE","tID","tMERIDIAN","tMINUTE_UNIT","tMONTH","tMONTH_UNIT","tSEC_UNIT",
  332. "tSNUMBER","tUNUMBER","tZONE","tDST","':'","','","'/'","spec","item","time",
  333. "zone","day","date","rel","relunit","number","o_merid",""
  334. };
  335. #endif
  336.  
  337. static const short yyr1[] = {     0,
  338.     19,    19,    20,    20,    20,    20,    20,    20,    21,    21,
  339.     21,    21,    21,    22,    22,    22,    23,    23,    23,    24,
  340.     24,    24,    24,    24,    24,    24,    25,    25,    26,    26,
  341.     26,    26,    26,    26,    26,    26,    26,    27,    28,    28
  342. };
  343.  
  344. static const short yyr2[] = {     0,
  345.      0,     2,     1,     1,     1,     1,     1,     1,     2,     4,
  346.      4,     6,     6,     1,     1,     2,     1,     2,     2,     3,
  347.      5,     3,     2,     4,     2,     3,     2,     1,     2,     2,
  348.      1,     2,     2,     1,     2,     2,     1,     1,     0,     1
  349. };
  350.  
  351. static const short yydefact[] = {     1,
  352.      0,    17,    15,    31,     0,    37,    34,     0,    38,    14,
  353.      2,     3,     4,     6,     5,     7,    28,     8,    18,    23,
  354.     30,    35,    32,    19,     9,    29,    25,    36,    33,     0,
  355.      0,     0,    16,    27,     0,    26,    22,    39,    20,    24,
  356.     40,    11,     0,    10,     0,    39,    21,    13,    12,     0,
  357.      0
  358. };
  359.  
  360. static const short yydefgoto[] = {     1,
  361.     11,    12,    13,    14,    15,    16,    17,    18,    44
  362. };
  363.  
  364. static const short yypact[] = {-32768,
  365.      0,   -15,-32768,-32768,   -10,-32768,-32768,    25,    11,    -8,
  366. -32768,-32768,-32768,-32768,-32768,-32768,    13,-32768,-32768,     7,
  367. -32768,-32768,-32768,-32768,-32768,-32768,     4,-32768,-32768,    14,
  368.     15,    19,-32768,-32768,    24,-32768,-32768,    18,    20,-32768,
  369. -32768,-32768,    26,-32768,    27,    -6,-32768,-32768,-32768,    31,
  370. -32768
  371. };
  372.  
  373. static const short yypgoto[] = {-32768,
  374. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,    -5
  375. };
  376.  
  377.  
  378. #define    YYLAST        41
  379.  
  380.  
  381. static const short yytable[] = {    50,
  382.     41,    19,    20,     2,     3,    48,    33,     4,     5,     6,
  383.      7,     8,     9,    10,    24,    34,    36,    25,    26,    27,
  384.     28,    29,    30,    35,    41,    37,    31,    38,    32,    42,
  385.     51,    39,    21,    43,    22,    23,    40,    45,    46,    47,
  386.     49
  387. };
  388.  
  389. static const short yycheck[] = {     0,
  390.      7,    17,    13,     4,     5,    12,    15,     8,     9,    10,
  391.     11,    12,    13,    14,     4,     3,    13,     7,     8,     9,
  392.     10,    11,    12,    17,     7,    12,    16,    13,    18,    12,
  393.      0,    13,     8,    16,    10,    11,    13,    18,    13,    13,
  394.     46
  395. };
  396. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  397. #line 3 "bison.simple"
  398.  
  399. /* Skeleton output parser for bison,
  400.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  401.  
  402.    This program is free software; you can redistribute it and/or modify
  403.    it under the terms of the GNU General Public License as published by
  404.    the Free Software Foundation; either version 1, or (at your option)
  405.    any later version.
  406.  
  407.    This program is distributed in the hope that it will be useful,
  408.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  409.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  410.    GNU General Public License for more details.
  411.  
  412.    You should have received a copy of the GNU General Public License
  413.    along with this program; if not, write to the Free Software
  414.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  415.  
  416.  
  417. #ifndef alloca
  418. #ifdef __GNUC__
  419. #define alloca __builtin_alloca
  420. #else /* not GNU C.  */
  421. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
  422. #include <alloca.h>
  423. #else /* not sparc */
  424. #if defined (MSDOS) && !defined (__TURBOC__)
  425. #include <malloc.h>
  426. #else /* not MSDOS, or __TURBOC__ */
  427. #if defined(_AIX)
  428. #include <malloc.h>
  429.  #pragma alloca
  430. #else /* not MSDOS, __TURBOC__, or _AIX */
  431. #ifdef __hpux
  432. #ifdef __cplusplus
  433. extern "C" {
  434. void *alloca (unsigned int);
  435. };
  436. #else /* not __cplusplus */
  437. void *alloca ();
  438. #endif /* not __cplusplus */
  439. #endif /* __hpux */
  440. #endif /* not _AIX */
  441. #endif /* not MSDOS, or __TURBOC__ */
  442. #endif /* not sparc.  */
  443. #endif /* not GNU C.  */
  444. #endif /* alloca not defined.  */
  445.  
  446. /* This is the parser code that is written into each bison parser
  447.   when the %semantic_parser declaration is not specified in the grammar.
  448.   It was written by Richard Stallman by simplifying the hairy parser
  449.   used when %semantic_parser is specified.  */
  450.  
  451. /* Note: there must be only one dollar sign in this file.
  452.    It is replaced by the list of actions, each action
  453.    as one case of the switch.  */
  454.  
  455. #define yyerrok        (yyerrstatus = 0)
  456. #define yyclearin    (yychar = YYEMPTY)
  457. #define YYEMPTY        -2
  458. #define YYEOF        0
  459. #define YYACCEPT    return(0)
  460. #define YYABORT     return(1)
  461. #define YYERROR        goto yyerrlab1
  462. /* Like YYERROR except do call yyerror.
  463.    This remains here temporarily to ease the
  464.    transition to the new meaning of YYERROR, for GCC.
  465.    Once GCC version 2 has supplanted version 1, this can go.  */
  466. #define YYFAIL        goto yyerrlab
  467. #define YYRECOVERING()  (!!yyerrstatus)
  468. #define YYBACKUP(token, value) \
  469. do                                \
  470.   if (yychar == YYEMPTY && yylen == 1)                \
  471.     { yychar = (token), yylval = (value);            \
  472.       yychar1 = YYTRANSLATE (yychar);                \
  473.       YYPOPSTACK;                        \
  474.       goto yybackup;                        \
  475.     }                                \
  476.   else                                \
  477.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  478. while (0)
  479.  
  480. #define YYTERROR    1
  481. #define YYERRCODE    256
  482.  
  483. #ifndef YYPURE
  484. #define YYLEX        yylex()
  485. #endif
  486.  
  487. #ifdef YYPURE
  488. #ifdef YYLSP_NEEDED
  489. #define YYLEX        yylex(&yylval, &yylloc)
  490. #else
  491. #define YYLEX        yylex(&yylval)
  492. #endif
  493. #endif
  494.  
  495. /* If nonreentrant, generate the variables here */
  496.  
  497. #ifndef YYPURE
  498.  
  499. int    yychar;            /*  the lookahead symbol        */
  500. YYSTYPE    yylval;            /*  the semantic value of the        */
  501.                 /*  lookahead symbol            */
  502.  
  503. #ifdef YYLSP_NEEDED
  504. YYLTYPE yylloc;            /*  location data for the lookahead    */
  505.                 /*  symbol                */
  506. #endif
  507.  
  508. int yynerrs;            /*  number of parse errors so far       */
  509. #endif  /* not YYPURE */
  510.  
  511. #if YYDEBUG != 0
  512. int yydebug;            /*  nonzero means print parse trace    */
  513. /* Since this is uninitialized, it does not stop multiple parsers
  514.    from coexisting.  */
  515. #endif
  516.  
  517. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  518.  
  519. #ifndef    YYINITDEPTH
  520. #define YYINITDEPTH 200
  521. #endif
  522.  
  523. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  524.     (effective only if the built-in stack extension method is used).  */
  525.  
  526. #if YYMAXDEPTH == 0
  527. #undef YYMAXDEPTH
  528. #endif
  529.  
  530. #ifndef YYMAXDEPTH
  531. #define YYMAXDEPTH 10000
  532. #endif
  533.  
  534. /* Prevent warning if -Wstrict-prototypes.  */
  535. #ifdef __GNUC__
  536. int yyparse (void);
  537. #endif
  538.  
  539. #if __GNUC__ > 1        /* GNU C and GNU C++ define this.  */
  540. #define __yy_bcopy(FROM,TO,COUNT)    __builtin_memcpy(TO,FROM,COUNT)
  541. #else                /* not GNU C or C++ */
  542. #ifndef __cplusplus
  543.  
  544. /* This is the most reliable way to avoid incompatibilities
  545.    in available built-in functions on various systems.  */
  546. static void
  547. __yy_bcopy (from, to, count)
  548.      char *from;
  549.      char *to;
  550.      int count;
  551. {
  552.   register char *f = from;
  553.   register char *t = to;
  554.   register int i = count;
  555.  
  556.   while (i-- > 0)
  557.     *t++ = *f++;
  558. }
  559.  
  560. #else /* __cplusplus */
  561.  
  562. /* This is the most reliable way to avoid incompatibilities
  563.    in available built-in functions on various systems.  */
  564. static void
  565. __yy_bcopy (char *from, char *to, int count)
  566. {
  567.   register char *f = from;
  568.   register char *t = to;
  569.   register int i = count;
  570.  
  571.   while (i-- > 0)
  572.     *t++ = *f++;
  573. }
  574.  
  575. #endif
  576. #endif
  577.  
  578. #line 184 "bison.simple"
  579. int
  580. yyparse()
  581. {
  582.   register int yystate;
  583.   register int yyn;
  584.   register short *yyssp;
  585.   register YYSTYPE *yyvsp;
  586.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  587.   int yychar1 = 0;        /*  lookahead token as an internal (translated) token number */
  588.  
  589.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  590.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  591.  
  592.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  593.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  594.  
  595. #ifdef YYLSP_NEEDED
  596.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  597.   YYLTYPE *yyls = yylsa;
  598.   YYLTYPE *yylsp;
  599.  
  600. #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
  601. #else
  602. #define YYPOPSTACK   (yyvsp--, yyssp--)
  603. #endif
  604.  
  605.   int yystacksize = YYINITDEPTH;
  606.  
  607. #ifdef YYPURE
  608.   int yychar;
  609.   YYSTYPE yylval;
  610.   int yynerrs;
  611. #ifdef YYLSP_NEEDED
  612.   YYLTYPE yylloc;
  613. #endif
  614. #endif
  615.  
  616.   YYSTYPE yyval;        /*  the variable used to return        */
  617.                 /*  semantic values from the action    */
  618.                 /*  routines                */
  619.  
  620.   int yylen;
  621.  
  622. #if YYDEBUG != 0
  623.   if (yydebug)
  624.     fprintf(stderr, "Starting parse\n");
  625. #endif
  626.  
  627.   yystate = 0;
  628.   yyerrstatus = 0;
  629.   yynerrs = 0;
  630.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  631.  
  632.   /* Initialize stack pointers.
  633.      Waste one element of value and location stack
  634.      so that they stay on the same level as the state stack.
  635.      The wasted elements are never initialized.  */
  636.  
  637.   yyssp = yyss - 1;
  638.   yyvsp = yyvs;
  639. #ifdef YYLSP_NEEDED
  640.   yylsp = yyls;
  641. #endif
  642.  
  643. /* Push a new state, which is found in  yystate  .  */
  644. /* In all cases, when you get here, the value and location stacks
  645.    have just been pushed. so pushing a state here evens the stacks.  */
  646. yynewstate:
  647.  
  648.   *++yyssp = yystate;
  649.  
  650.   if (yyssp >= yyss + yystacksize - 1)
  651.     {
  652.       /* Give user a chance to reallocate the stack */
  653.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  654.       YYSTYPE *yyvs1 = yyvs;
  655.       short *yyss1 = yyss;
  656. #ifdef YYLSP_NEEDED
  657.       YYLTYPE *yyls1 = yyls;
  658. #endif
  659.  
  660.       /* Get the current used size of the three stacks, in elements.  */
  661.       int size = yyssp - yyss + 1;
  662.  
  663. #ifdef yyoverflow
  664.       /* Each stack pointer address is followed by the size of
  665.      the data in use in that stack, in bytes.  */
  666. #ifdef YYLSP_NEEDED
  667.       /* This used to be a conditional around just the two extra args,
  668.      but that might be undefined if yyoverflow is a macro.  */
  669.       yyoverflow("parser stack overflow",
  670.          &yyss1, size * sizeof (*yyssp),
  671.          &yyvs1, size * sizeof (*yyvsp),
  672.          &yyls1, size * sizeof (*yylsp),
  673.          &yystacksize);
  674. #else
  675.       yyoverflow("parser stack overflow",
  676.          &yyss1, size * sizeof (*yyssp),
  677.          &yyvs1, size * sizeof (*yyvsp),
  678.          &yystacksize);
  679. #endif
  680.  
  681.       yyss = yyss1; yyvs = yyvs1;
  682. #ifdef YYLSP_NEEDED
  683.       yyls = yyls1;
  684. #endif
  685. #else /* no yyoverflow */
  686.       /* Extend the stack our own way.  */
  687.       if (yystacksize >= YYMAXDEPTH)
  688.     {
  689.       yyerror("parser stack overflow");
  690.       return 2;
  691.     }
  692.       yystacksize *= 2;
  693.       if (yystacksize > YYMAXDEPTH)
  694.     yystacksize = YYMAXDEPTH;
  695.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  696.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  697.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  698.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  699. #ifdef YYLSP_NEEDED
  700.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  701.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  702. #endif
  703. #endif /* no yyoverflow */
  704.  
  705.       yyssp = yyss + size - 1;
  706.       yyvsp = yyvs + size - 1;
  707. #ifdef YYLSP_NEEDED
  708.       yylsp = yyls + size - 1;
  709. #endif
  710.  
  711. #if YYDEBUG != 0
  712.       if (yydebug)
  713.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  714. #endif
  715.  
  716.       if (yyssp >= yyss + yystacksize - 1)
  717.     YYABORT;
  718.     }
  719.  
  720. #if YYDEBUG != 0
  721.   if (yydebug)
  722.     fprintf(stderr, "Entering state %d\n", yystate);
  723. #endif
  724.  
  725.   goto yybackup;
  726.  yybackup:
  727.  
  728. /* Do appropriate processing given the current state.  */
  729. /* Read a lookahead token if we need one and don't already have one.  */
  730. /* yyresume: */
  731.  
  732.   /* First try to decide what to do without reference to lookahead token.  */
  733.  
  734.   yyn = yypact[yystate];
  735.   if (yyn == YYFLAG)
  736.     goto yydefault;
  737.  
  738.   /* Not known => get a lookahead token if don't already have one.  */
  739.  
  740.   /* yychar is either YYEMPTY or YYEOF
  741.      or a valid token in external form.  */
  742.  
  743.   if (yychar == YYEMPTY)
  744.     {
  745. #if YYDEBUG != 0
  746.       if (yydebug)
  747.     fprintf(stderr, "Reading a token: ");
  748. #endif
  749.       yychar = YYLEX;
  750.     }
  751.  
  752.   /* Convert token to internal form (in yychar1) for indexing tables with */
  753.  
  754.   if (yychar <= 0)        /* This means end of input. */
  755.     {
  756.       yychar1 = 0;
  757.       yychar = YYEOF;        /* Don't call YYLEX any more */
  758.  
  759. #if YYDEBUG != 0
  760.       if (yydebug)
  761.     fprintf(stderr, "Now at end of input.\n");
  762. #endif
  763.     }
  764.   else
  765.     {
  766.       yychar1 = YYTRANSLATE(yychar);
  767.  
  768. #if YYDEBUG != 0
  769.       if (yydebug)
  770.     {
  771.       fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
  772.       /* Give the individual parser a way to print the precise meaning
  773.          of a token, for further debugging info.  */
  774. #ifdef YYPRINT
  775.       YYPRINT (stderr, yychar, yylval);
  776. #endif
  777.       fprintf (stderr, ")\n");
  778.     }
  779. #endif
  780.     }
  781.  
  782.   yyn += yychar1;
  783.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  784.     goto yydefault;
  785.  
  786.   yyn = yytable[yyn];
  787.  
  788.   /* yyn is what to do for this token type in this state.
  789.      Negative => reduce, -yyn is rule number.
  790.      Positive => shift, yyn is new state.
  791.        New state is final state => don't bother to shift,
  792.        just return success.
  793.      0, or most negative number => error.  */
  794.  
  795.   if (yyn < 0)
  796.     {
  797.       if (yyn == YYFLAG)
  798.     goto yyerrlab;
  799.       yyn = -yyn;
  800.       goto yyreduce;
  801.     }
  802.   else if (yyn == 0)
  803.     goto yyerrlab;
  804.  
  805.   if (yyn == YYFINAL)
  806.     YYACCEPT;
  807.  
  808.   /* Shift the lookahead token.  */
  809.  
  810. #if YYDEBUG != 0
  811.   if (yydebug)
  812.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  813. #endif
  814.  
  815.   /* Discard the token being shifted unless it is eof.  */
  816.   if (yychar != YYEOF)
  817.     yychar = YYEMPTY;
  818.  
  819.   *++yyvsp = yylval;
  820. #ifdef YYLSP_NEEDED
  821.   *++yylsp = yylloc;
  822. #endif
  823.  
  824.   /* count tokens shifted since error; after three, turn off error status.  */
  825.   if (yyerrstatus) yyerrstatus--;
  826.  
  827.   yystate = yyn;
  828.   goto yynewstate;
  829.  
  830. /* Do the default action for the current state.  */
  831. yydefault:
  832.  
  833.   yyn = yydefact[yystate];
  834.   if (yyn == 0)
  835.     goto yyerrlab;
  836.  
  837. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  838. yyreduce:
  839.   yylen = yyr2[yyn];
  840.   if (yylen > 0)
  841.     yyval = yyvsp[1-yylen]; /* implement default value of the action */
  842.  
  843. #if YYDEBUG != 0
  844.   if (yydebug)
  845.     {
  846.       int i;
  847.  
  848.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  849.            yyn, yyrline[yyn]);
  850.  
  851.       /* Print the symbols being reduced, and their result.  */
  852.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  853.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  854.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  855.     }
  856. #endif
  857.  
  858.  
  859.   switch (yyn) {
  860.  
  861. case 3:
  862. #line 227 "getdate.y"
  863. {
  864.         yyHaveTime++;
  865.     ;
  866.     break;}
  867. case 4:
  868. #line 230 "getdate.y"
  869. {
  870.         yyHaveZone++;
  871.     ;
  872.     break;}
  873. case 5:
  874. #line 233 "getdate.y"
  875. {
  876.         yyHaveDate++;
  877.     ;
  878.     break;}
  879. case 6:
  880. #line 236 "getdate.y"
  881. {
  882.         yyHaveDay++;
  883.     ;
  884.     break;}
  885. case 7:
  886. #line 239 "getdate.y"
  887. {
  888.         yyHaveRel++;
  889.     ;
  890.     break;}
  891. case 9:
  892. #line 245 "getdate.y"
  893. {
  894.         yyHour = yyvsp[-1].Number;
  895.         yyMinutes = 0;
  896.         yySeconds = 0;
  897.         yyMeridian = yyvsp[0].Meridian;
  898.     ;
  899.     break;}
  900. case 10:
  901. #line 251 "getdate.y"
  902. {
  903.         yyHour = yyvsp[-3].Number;
  904.         yyMinutes = yyvsp[-1].Number;
  905.         yySeconds = 0;
  906.         yyMeridian = yyvsp[0].Meridian;
  907.     ;
  908.     break;}
  909. case 11:
  910. #line 257 "getdate.y"
  911. {
  912.         yyHour = yyvsp[-3].Number;
  913.         yyMinutes = yyvsp[-1].Number;
  914.         yyMeridian = MER24;
  915.         yyDSTmode = DSToff;
  916.         yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
  917.     ;
  918.     break;}
  919. case 12:
  920. #line 264 "getdate.y"
  921. {
  922.         yyHour = yyvsp[-5].Number;
  923.         yyMinutes = yyvsp[-3].Number;
  924.         yySeconds = yyvsp[-1].Number;
  925.         yyMeridian = yyvsp[0].Meridian;
  926.     ;
  927.     break;}
  928. case 13:
  929. #line 270 "getdate.y"
  930. {
  931.         yyHour = yyvsp[-5].Number;
  932.         yyMinutes = yyvsp[-3].Number;
  933.         yySeconds = yyvsp[-1].Number;
  934.         yyMeridian = MER24;
  935.         yyDSTmode = DSToff;
  936.         yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
  937.     ;
  938.     break;}
  939. case 14:
  940. #line 280 "getdate.y"
  941. {
  942.         yyTimezone = yyvsp[0].Number;
  943.         yyDSTmode = DSToff;
  944.     ;
  945.     break;}
  946. case 15:
  947. #line 284 "getdate.y"
  948. {
  949.         yyTimezone = yyvsp[0].Number;
  950.         yyDSTmode = DSTon;
  951.     ;
  952.     break;}
  953. case 16:
  954. #line 289 "getdate.y"
  955. {
  956.         yyTimezone = yyvsp[-1].Number;
  957.         yyDSTmode = DSTon;
  958.     ;
  959.     break;}
  960. case 17:
  961. #line 295 "getdate.y"
  962. {
  963.         yyDayOrdinal = 1;
  964.         yyDayNumber = yyvsp[0].Number;
  965.     ;
  966.     break;}
  967. case 18:
  968. #line 299 "getdate.y"
  969. {
  970.         yyDayOrdinal = 1;
  971.         yyDayNumber = yyvsp[-1].Number;
  972.     ;
  973.     break;}
  974. case 19:
  975. #line 303 "getdate.y"
  976. {
  977.         yyDayOrdinal = yyvsp[-1].Number;
  978.         yyDayNumber = yyvsp[0].Number;
  979.     ;
  980.     break;}
  981. case 20:
  982. #line 309 "getdate.y"
  983. {
  984.         yyMonth = yyvsp[-2].Number;
  985.         yyDay = yyvsp[0].Number;
  986.     ;
  987.     break;}
  988. case 21:
  989. #line 313 "getdate.y"
  990. {
  991.         yyMonth = yyvsp[-4].Number;
  992.         yyDay = yyvsp[-2].Number;
  993.         yyYear = yyvsp[0].Number;
  994.     ;
  995.     break;}
  996. case 22:
  997. #line 318 "getdate.y"
  998. {
  999.         /* ISO 8601 format.  yyyy-mm-dd.  */
  1000.         yyYear = yyvsp[-2].Number;
  1001.         yyMonth = -yyvsp[-1].Number;
  1002.         yyDay = -yyvsp[0].Number;
  1003.     ;
  1004.     break;}
  1005. case 23:
  1006. #line 324 "getdate.y"
  1007. {
  1008.         yyMonth = yyvsp[-1].Number;
  1009.         yyDay = yyvsp[0].Number;
  1010.     ;
  1011.     break;}
  1012. case 24:
  1013. #line 328 "getdate.y"
  1014. {
  1015.         yyMonth = yyvsp[-3].Number;
  1016.         yyDay = yyvsp[-2].Number;
  1017.         yyYear = yyvsp[0].Number;
  1018.     ;
  1019.     break;}
  1020. case 25:
  1021. #line 333 "getdate.y"
  1022. {
  1023.         yyMonth = yyvsp[0].Number;
  1024.         yyDay = yyvsp[-1].Number;
  1025.     ;
  1026.     break;}
  1027. case 26:
  1028. #line 337 "getdate.y"
  1029. {
  1030.         yyMonth = yyvsp[-1].Number;
  1031.         yyDay = yyvsp[-2].Number;
  1032.         yyYear = yyvsp[0].Number;
  1033.     ;
  1034.     break;}
  1035. case 27:
  1036. #line 344 "getdate.y"
  1037. {
  1038.         yyRelSeconds = -yyRelSeconds;
  1039.         yyRelMonth = -yyRelMonth;
  1040.     ;
  1041.     break;}
  1042. case 29:
  1043. #line 351 "getdate.y"
  1044. {
  1045.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
  1046.     ;
  1047.     break;}
  1048. case 30:
  1049. #line 354 "getdate.y"
  1050. {
  1051.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
  1052.     ;
  1053.     break;}
  1054. case 31:
  1055. #line 357 "getdate.y"
  1056. {
  1057.         yyRelSeconds += yyvsp[0].Number * 60L;
  1058.     ;
  1059.     break;}
  1060. case 32:
  1061. #line 360 "getdate.y"
  1062. {
  1063.         yyRelSeconds += yyvsp[-1].Number;
  1064.     ;
  1065.     break;}
  1066. case 33:
  1067. #line 363 "getdate.y"
  1068. {
  1069.         yyRelSeconds += yyvsp[-1].Number;
  1070.     ;
  1071.     break;}
  1072. case 34:
  1073. #line 366 "getdate.y"
  1074. {
  1075.         yyRelSeconds++;
  1076.     ;
  1077.     break;}
  1078. case 35:
  1079. #line 369 "getdate.y"
  1080. {
  1081.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  1082.     ;
  1083.     break;}
  1084. case 36:
  1085. #line 372 "getdate.y"
  1086. {
  1087.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  1088.     ;
  1089.     break;}
  1090. case 37:
  1091. #line 375 "getdate.y"
  1092. {
  1093.         yyRelMonth += yyvsp[0].Number;
  1094.     ;
  1095.     break;}
  1096. case 38:
  1097. #line 380 "getdate.y"
  1098. {
  1099.         if (yyHaveTime && yyHaveDate && !yyHaveRel)
  1100.         yyYear = yyvsp[0].Number;
  1101.         else {
  1102.         if(yyvsp[0].Number>10000) {
  1103.             time_t date_part;
  1104.  
  1105.             date_part= yyvsp[0].Number/10000;
  1106.             yyHaveDate++;
  1107.             yyDay= (date_part)%100;
  1108.             yyMonth= (date_part/100)%100;
  1109.             yyYear = date_part/10000;
  1110.         } 
  1111.             yyHaveTime++;
  1112.         if (yyvsp[0].Number < 100) {
  1113.             yyHour = yyvsp[0].Number;
  1114.             yyMinutes = 0;
  1115.         }
  1116.         else {
  1117.             yyHour = yyvsp[0].Number / 100;
  1118.             yyMinutes = yyvsp[0].Number % 100;
  1119.         }
  1120.         yySeconds = 0;
  1121.         yyMeridian = MER24;
  1122.         }
  1123.     ;
  1124.     break;}
  1125. case 39:
  1126. #line 408 "getdate.y"
  1127. {
  1128.         yyval.Meridian = MER24;
  1129.     ;
  1130.     break;}
  1131. case 40:
  1132. #line 411 "getdate.y"
  1133. {
  1134.         yyval.Meridian = yyvsp[0].Meridian;
  1135.     ;
  1136.     break;}
  1137. }
  1138.    /* the action file gets copied in in place of this dollarsign */
  1139. #line 465 "bison.simple"
  1140.  
  1141.   yyvsp -= yylen;
  1142.   yyssp -= yylen;
  1143. #ifdef YYLSP_NEEDED
  1144.   yylsp -= yylen;
  1145. #endif
  1146.  
  1147. #if YYDEBUG != 0
  1148.   if (yydebug)
  1149.     {
  1150.       short *ssp1 = yyss - 1;
  1151.       fprintf (stderr, "state stack now");
  1152.       while (ssp1 != yyssp)
  1153.     fprintf (stderr, " %d", *++ssp1);
  1154.       fprintf (stderr, "\n");
  1155.     }
  1156. #endif
  1157.  
  1158.   *++yyvsp = yyval;
  1159.  
  1160. #ifdef YYLSP_NEEDED
  1161.   yylsp++;
  1162.   if (yylen == 0)
  1163.     {
  1164.       yylsp->first_line = yylloc.first_line;
  1165.       yylsp->first_column = yylloc.first_column;
  1166.       yylsp->last_line = (yylsp-1)->last_line;
  1167.       yylsp->last_column = (yylsp-1)->last_column;
  1168.       yylsp->text = 0;
  1169.     }
  1170.   else
  1171.     {
  1172.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1173.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1174.     }
  1175. #endif
  1176.  
  1177.   /* Now "shift" the result of the reduction.
  1178.      Determine what state that goes to,
  1179.      based on the state we popped back to
  1180.      and the rule number reduced by.  */
  1181.  
  1182.   yyn = yyr1[yyn];
  1183.  
  1184.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1185.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1186.     yystate = yytable[yystate];
  1187.   else
  1188.     yystate = yydefgoto[yyn - YYNTBASE];
  1189.  
  1190.   goto yynewstate;
  1191.  
  1192. yyerrlab:   /* here on detecting error */
  1193.  
  1194.   if (! yyerrstatus)
  1195.     /* If not already recovering from an error, report this error.  */
  1196.     {
  1197.       ++yynerrs;
  1198.  
  1199. #ifdef YYERROR_VERBOSE
  1200.       yyn = yypact[yystate];
  1201.  
  1202.       if (yyn > YYFLAG && yyn < YYLAST)
  1203.     {
  1204.       int size = 0;
  1205.       char *msg;
  1206.       int x, count;
  1207.  
  1208.       count = 0;
  1209.       /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */
  1210.       for (x = (yyn < 0 ? -yyn : 0);
  1211.            x < (sizeof(yytname) / sizeof(char *)); x++)
  1212.         if (yycheck[x + yyn] == x)
  1213.           size += strlen(yytname[x]) + 15, count++;
  1214.       msg = (char *) malloc(size + 15);
  1215.       if (msg != 0)
  1216.         {
  1217.           strcpy(msg, "parse error");
  1218.  
  1219.           if (count < 5)
  1220.         {
  1221.           count = 0;
  1222.           for (x = (yyn < 0 ? -yyn : 0);
  1223.                x < (sizeof(yytname) / sizeof(char *)); x++)
  1224.             if (yycheck[x + yyn] == x)
  1225.               {
  1226.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  1227.             strcat(msg, yytname[x]);
  1228.             strcat(msg, "'");
  1229.             count++;
  1230.               }
  1231.         }
  1232.           yyerror(msg);
  1233.           free(msg);
  1234.         }
  1235.       else
  1236.         yyerror ("parse error; also virtual memory exceeded");
  1237.     }
  1238.       else
  1239. #endif /* YYERROR_VERBOSE */
  1240.     yyerror("parse error");
  1241.     }
  1242.  
  1243.   goto yyerrlab1;
  1244. yyerrlab1:   /* here on error raised explicitly by an action */
  1245.  
  1246.   if (yyerrstatus == 3)
  1247.     {
  1248.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1249.  
  1250.       /* return failure if at end of input */
  1251.       if (yychar == YYEOF)
  1252.     YYABORT;
  1253.  
  1254. #if YYDEBUG != 0
  1255.       if (yydebug)
  1256.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1257. #endif
  1258.  
  1259.       yychar = YYEMPTY;
  1260.     }
  1261.  
  1262.   /* Else will try to reuse lookahead token
  1263.      after shifting the error token.  */
  1264.  
  1265.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1266.  
  1267.   goto yyerrhandle;
  1268.  
  1269. yyerrdefault:  /* current state does not do anything special for the error token. */
  1270.  
  1271. #if 0
  1272.   /* This is wrong; only states that explicitly want error tokens
  1273.      should shift them.  */
  1274.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1275.   if (yyn) goto yydefault;
  1276. #endif
  1277.  
  1278. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1279.  
  1280.   if (yyssp == yyss) YYABORT;
  1281.   yyvsp--;
  1282.   yystate = *--yyssp;
  1283. #ifdef YYLSP_NEEDED
  1284.   yylsp--;
  1285. #endif
  1286.  
  1287. #if YYDEBUG != 0
  1288.   if (yydebug)
  1289.     {
  1290.       short *ssp1 = yyss - 1;
  1291.       fprintf (stderr, "Error: state stack now");
  1292.       while (ssp1 != yyssp)
  1293.     fprintf (stderr, " %d", *++ssp1);
  1294.       fprintf (stderr, "\n");
  1295.     }
  1296. #endif
  1297.  
  1298. yyerrhandle:
  1299.  
  1300.   yyn = yypact[yystate];
  1301.   if (yyn == YYFLAG)
  1302.     goto yyerrdefault;
  1303.  
  1304.   yyn += YYTERROR;
  1305.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1306.     goto yyerrdefault;
  1307.  
  1308.   yyn = yytable[yyn];
  1309.   if (yyn < 0)
  1310.     {
  1311.       if (yyn == YYFLAG)
  1312.     goto yyerrpop;
  1313.       yyn = -yyn;
  1314.       goto yyreduce;
  1315.     }
  1316.   else if (yyn == 0)
  1317.     goto yyerrpop;
  1318.  
  1319.   if (yyn == YYFINAL)
  1320.     YYACCEPT;
  1321.  
  1322. #if YYDEBUG != 0
  1323.   if (yydebug)
  1324.     fprintf(stderr, "Shifting error token, ");
  1325. #endif
  1326.  
  1327.   *++yyvsp = yylval;
  1328. #ifdef YYLSP_NEEDED
  1329.   *++yylsp = yylloc;
  1330. #endif
  1331.  
  1332.   yystate = yyn;
  1333.   goto yynewstate;
  1334. }
  1335. #line 416 "getdate.y"
  1336.  
  1337.  
  1338. /* Month and day table. */
  1339. static TABLE const MonthDayTable[] = {
  1340.     { "january",    tMONTH,  1 },
  1341.     { "february",    tMONTH,  2 },
  1342.     { "march",        tMONTH,  3 },
  1343.     { "april",        tMONTH,  4 },
  1344.     { "may",        tMONTH,  5 },
  1345.     { "june",        tMONTH,  6 },
  1346.     { "july",        tMONTH,  7 },
  1347.     { "august",        tMONTH,  8 },
  1348.     { "september",    tMONTH,  9 },
  1349.     { "sept",        tMONTH,  9 },
  1350.     { "october",    tMONTH, 10 },
  1351.     { "november",    tMONTH, 11 },
  1352.     { "december",    tMONTH, 12 },
  1353.     { "sunday",        tDAY, 0 },
  1354.     { "monday",        tDAY, 1 },
  1355.     { "tuesday",    tDAY, 2 },
  1356.     { "tues",        tDAY, 2 },
  1357.     { "wednesday",    tDAY, 3 },
  1358.     { "wednes",        tDAY, 3 },
  1359.     { "thursday",    tDAY, 4 },
  1360.     { "thur",        tDAY, 4 },
  1361.     { "thurs",        tDAY, 4 },
  1362.     { "friday",        tDAY, 5 },
  1363.     { "saturday",    tDAY, 6 },
  1364.     { NULL }
  1365. };
  1366.  
  1367. /* Time units table. */
  1368. static TABLE const UnitsTable[] = {
  1369.     { "year",        tMONTH_UNIT,    12 },
  1370.     { "month",        tMONTH_UNIT,    1 },
  1371.     { "fortnight",    tMINUTE_UNIT,    14 * 24 * 60 },
  1372.     { "week",        tMINUTE_UNIT,    7 * 24 * 60 },
  1373.     { "day",        tMINUTE_UNIT,    1 * 24 * 60 },
  1374.     { "hour",        tMINUTE_UNIT,    60 },
  1375.     { "minute",        tMINUTE_UNIT,    1 },
  1376.     { "min",        tMINUTE_UNIT,    1 },
  1377.     { "second",        tSEC_UNIT,    1 },
  1378.     { "sec",        tSEC_UNIT,    1 },
  1379.     { NULL }
  1380. };
  1381.  
  1382. /* Assorted relative-time words. */
  1383. static TABLE const OtherTable[] = {
  1384.     { "tomorrow",    tMINUTE_UNIT,    1 * 24 * 60 },
  1385.     { "yesterday",    tMINUTE_UNIT,    -1 * 24 * 60 },
  1386.     { "today",        tMINUTE_UNIT,    0 },
  1387.     { "now",        tMINUTE_UNIT,    0 },
  1388.     { "last",        tUNUMBER,    -1 },
  1389.     { "this",        tMINUTE_UNIT,    0 },
  1390.     { "next",        tUNUMBER,    2 },
  1391.     { "first",        tUNUMBER,    1 },
  1392. /*  { "second",        tUNUMBER,    2 }, */
  1393.     { "third",        tUNUMBER,    3 },
  1394.     { "fourth",        tUNUMBER,    4 },
  1395.     { "fifth",        tUNUMBER,    5 },
  1396.     { "sixth",        tUNUMBER,    6 },
  1397.     { "seventh",    tUNUMBER,    7 },
  1398.     { "eighth",        tUNUMBER,    8 },
  1399.     { "ninth",        tUNUMBER,    9 },
  1400.     { "tenth",        tUNUMBER,    10 },
  1401.     { "eleventh",    tUNUMBER,    11 },
  1402.     { "twelfth",    tUNUMBER,    12 },
  1403.     { "ago",        tAGO,    1 },
  1404.     { NULL }
  1405. };
  1406.  
  1407. /* The timezone table. */
  1408. /* Some of these are commented out because a time_t can't store a float. */
  1409. static TABLE const TimezoneTable[] = {
  1410.     { "gmt",    tZONE,     HOUR( 0) },    /* Greenwich Mean */
  1411.     { "ut",    tZONE,     HOUR( 0) },    /* Universal (Coordinated) */
  1412.     { "utc",    tZONE,     HOUR( 0) },
  1413.     { "wet",    tZONE,     HOUR( 0) },    /* Western European */
  1414.     { "bst",    tDAYZONE,  HOUR( 0) },    /* British Summer */
  1415.     { "wat",    tZONE,     HOUR( 1) },    /* West Africa */
  1416.     { "at",    tZONE,     HOUR( 2) },    /* Azores */
  1417. #if    0
  1418.     /* For completeness.  BST is also British Summer, and GST is
  1419.      * also Guam Standard. */
  1420.     { "bst",    tZONE,     HOUR( 3) },    /* Brazil Standard */
  1421.     { "gst",    tZONE,     HOUR( 3) },    /* Greenland Standard */
  1422. #endif
  1423. #if 0
  1424.     { "nft",    tZONE,     HOUR(3.5) },    /* Newfoundland */
  1425.     { "nst",    tZONE,     HOUR(3.5) },    /* Newfoundland Standard */
  1426.     { "ndt",    tDAYZONE,  HOUR(3.5) },    /* Newfoundland Daylight */
  1427. #endif
  1428.     { "ast",    tZONE,     HOUR( 4) },    /* Atlantic Standard */
  1429.     { "adt",    tDAYZONE,  HOUR( 4) },    /* Atlantic Daylight */
  1430.     { "est",    tZONE,     HOUR( 5) },    /* Eastern Standard */
  1431.     { "edt",    tDAYZONE,  HOUR( 5) },    /* Eastern Daylight */
  1432.     { "cst",    tZONE,     HOUR( 6) },    /* Central Standard */
  1433.     { "cdt",    tDAYZONE,  HOUR( 6) },    /* Central Daylight */
  1434.     { "mst",    tZONE,     HOUR( 7) },    /* Mountain Standard */
  1435.     { "mdt",    tDAYZONE,  HOUR( 7) },    /* Mountain Daylight */
  1436.     { "pst",    tZONE,     HOUR( 8) },    /* Pacific Standard */
  1437.     { "pdt",    tDAYZONE,  HOUR( 8) },    /* Pacific Daylight */
  1438.     { "yst",    tZONE,     HOUR( 9) },    /* Yukon Standard */
  1439.     { "ydt",    tDAYZONE,  HOUR( 9) },    /* Yukon Daylight */
  1440.     { "hst",    tZONE,     HOUR(10) },    /* Hawaii Standard */
  1441.     { "hdt",    tDAYZONE,  HOUR(10) },    /* Hawaii Daylight */
  1442.     { "cat",    tZONE,     HOUR(10) },    /* Central Alaska */
  1443.     { "ahst",    tZONE,     HOUR(10) },    /* Alaska-Hawaii Standard */
  1444.     { "nt",    tZONE,     HOUR(11) },    /* Nome */
  1445.     { "idlw",    tZONE,     HOUR(12) },    /* International Date Line West */
  1446.     { "cet",    tZONE,     -HOUR(1) },    /* Central European */
  1447.     { "met",    tZONE,     -HOUR(1) },    /* Middle European */
  1448.     { "mewt",    tZONE,     -HOUR(1) },    /* Middle European Winter */
  1449.     { "mest",    tDAYZONE,  -HOUR(1) },    /* Middle European Summer */
  1450.     { "swt",    tZONE,     -HOUR(1) },    /* Swedish Winter */
  1451.     { "sst",    tDAYZONE,  -HOUR(1) },    /* Swedish Summer */
  1452.     { "fwt",    tZONE,     -HOUR(1) },    /* French Winter */
  1453.     { "fst",    tDAYZONE,  -HOUR(1) },    /* French Summer */
  1454.     { "eet",    tZONE,     -HOUR(2) },    /* Eastern Europe, USSR Zone 1 */
  1455.     { "bt",    tZONE,     -HOUR(3) },    /* Baghdad, USSR Zone 2 */
  1456. #if 0
  1457.     { "it",    tZONE,     -HOUR(3.5) },/* Iran */
  1458. #endif
  1459.     { "zp4",    tZONE,     -HOUR(4) },    /* USSR Zone 3 */
  1460.     { "zp5",    tZONE,     -HOUR(5) },    /* USSR Zone 4 */
  1461. #if 0
  1462.     { "ist",    tZONE,     -HOUR(5.5) },/* Indian Standard */
  1463. #endif
  1464.     { "zp6",    tZONE,     -HOUR(6) },    /* USSR Zone 5 */
  1465. #if    0
  1466.     /* For completeness.  NST is also Newfoundland Stanard, and SST is
  1467.      * also Swedish Summer. */
  1468.     { "nst",    tZONE,     -HOUR(6.5) },/* North Sumatra */
  1469.     { "sst",    tZONE,     -HOUR(7) },    /* South Sumatra, USSR Zone 6 */
  1470. #endif    /* 0 */
  1471.     { "wast",    tZONE,     -HOUR(7) },    /* West Australian Standard */
  1472.     { "wadt",    tDAYZONE,  -HOUR(7) },    /* West Australian Daylight */
  1473. #if 0
  1474.     { "jt",    tZONE,     -HOUR(7.5) },/* Java (3pm in Cronusland!) */
  1475. #endif
  1476.     { "cct",    tZONE,     -HOUR(8) },    /* China Coast, USSR Zone 7 */
  1477.     { "jst",    tZONE,     -HOUR(9) },    /* Japan Standard, USSR Zone 8 */
  1478. #if 0
  1479.     { "cast",    tZONE,     -HOUR(9.5) },/* Central Australian Standard */
  1480.     { "cadt",    tDAYZONE,  -HOUR(9.5) },/* Central Australian Daylight */
  1481. #endif
  1482.     { "east",    tZONE,     -HOUR(10) },    /* Eastern Australian Standard */
  1483.     { "eadt",    tDAYZONE,  -HOUR(10) },    /* Eastern Australian Daylight */
  1484.     { "gst",    tZONE,     -HOUR(10) },    /* Guam Standard, USSR Zone 9 */
  1485.     { "nzt",    tZONE,     -HOUR(12) },    /* New Zealand */
  1486.     { "nzst",    tZONE,     -HOUR(12) },    /* New Zealand Standard */
  1487.     { "nzdt",    tDAYZONE,  -HOUR(12) },    /* New Zealand Daylight */
  1488.     { "idle",    tZONE,     -HOUR(12) },    /* International Date Line East */
  1489.     {  NULL  }
  1490. };
  1491.  
  1492. /* Military timezone table. */
  1493. static TABLE const MilitaryTable[] = {
  1494.     { "a",    tZONE,    HOUR(  1) },
  1495.     { "b",    tZONE,    HOUR(  2) },
  1496.     { "c",    tZONE,    HOUR(  3) },
  1497.     { "d",    tZONE,    HOUR(  4) },
  1498.     { "e",    tZONE,    HOUR(  5) },
  1499.     { "f",    tZONE,    HOUR(  6) },
  1500.     { "g",    tZONE,    HOUR(  7) },
  1501.     { "h",    tZONE,    HOUR(  8) },
  1502.     { "i",    tZONE,    HOUR(  9) },
  1503.     { "k",    tZONE,    HOUR( 10) },
  1504.     { "l",    tZONE,    HOUR( 11) },
  1505.     { "m",    tZONE,    HOUR( 12) },
  1506.     { "n",    tZONE,    HOUR(- 1) },
  1507.     { "o",    tZONE,    HOUR(- 2) },
  1508.     { "p",    tZONE,    HOUR(- 3) },
  1509.     { "q",    tZONE,    HOUR(- 4) },
  1510.     { "r",    tZONE,    HOUR(- 5) },
  1511.     { "s",    tZONE,    HOUR(- 6) },
  1512.     { "t",    tZONE,    HOUR(- 7) },
  1513.     { "u",    tZONE,    HOUR(- 8) },
  1514.     { "v",    tZONE,    HOUR(- 9) },
  1515.     { "w",    tZONE,    HOUR(-10) },
  1516.     { "x",    tZONE,    HOUR(-11) },
  1517.     { "y",    tZONE,    HOUR(-12) },
  1518.     { "z",    tZONE,    HOUR(  0) },
  1519.     { NULL }
  1520. };
  1521.  
  1522.  
  1523.  
  1524.  
  1525. /* ARGSUSED */
  1526. static int
  1527. yyerror(s)
  1528.     char    *s;
  1529. {
  1530.   return 0;
  1531. }
  1532.  
  1533.  
  1534. static time_t
  1535. ToSeconds(Hours, Minutes, Seconds, Meridian)
  1536.     time_t    Hours;
  1537.     time_t    Minutes;
  1538.     time_t    Seconds;
  1539.     MERIDIAN    Meridian;
  1540. {
  1541.     if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59)
  1542.     return -1;
  1543.     switch (Meridian) {
  1544.     case MER24:
  1545.     if (Hours < 0 || Hours > 23)
  1546.         return -1;
  1547.     return (Hours * 60L + Minutes) * 60L + Seconds;
  1548.     case MERam:
  1549.     if (Hours < 1 || Hours > 12)
  1550.         return -1;
  1551.     return (Hours * 60L + Minutes) * 60L + Seconds;
  1552.     case MERpm:
  1553.     if (Hours < 1 || Hours > 12)
  1554.         return -1;
  1555.     return ((Hours + 12) * 60L + Minutes) * 60L + Seconds;
  1556.     default:
  1557.     abort ();
  1558.     }
  1559.     /* NOTREACHED */
  1560. }
  1561.  
  1562.  
  1563. static time_t
  1564. Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode)
  1565.     time_t    Month;
  1566.     time_t    Day;
  1567.     time_t    Year;
  1568.     time_t    Hours;
  1569.     time_t    Minutes;
  1570.     time_t    Seconds;
  1571.     MERIDIAN    Meridian;
  1572.     DSTMODE    DSTmode;
  1573. {
  1574.     static int DaysInMonth[12] = {
  1575.     31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  1576.     };
  1577.     time_t    tod;
  1578.     time_t    Julian;
  1579.     int        i;
  1580.  
  1581.     if (Year < 0)
  1582.     Year = -Year;
  1583.     if (Year < 100)
  1584.     Year += 1900;
  1585.     DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0)
  1586.             ? 29 : 28;
  1587.     if (Year < EPOCH || Year > 1999
  1588.      || Month < 1 || Month > 12
  1589.      /* Lint fluff:  "conversion from long may lose accuracy" */
  1590.      || Day < 1 || Day > DaysInMonth[(int)--Month])
  1591.     return -1;
  1592.  
  1593.     for (Julian = Day - 1, i = 0; i < Month; i++)
  1594.     Julian += DaysInMonth[i];
  1595.     for (i = EPOCH; i < Year; i++)
  1596.     Julian += 365 + (i % 4 == 0);
  1597.     Julian *= SECSPERDAY;
  1598.     Julian += yyTimezone * 60L;
  1599.     if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
  1600.     return -1;
  1601.     Julian += tod;
  1602.     if (DSTmode == DSTon
  1603.      || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst))
  1604.     Julian -= 60 * 60;
  1605.     return Julian;
  1606. }
  1607.  
  1608.  
  1609. static time_t
  1610. DSTcorrect(Start, Future)
  1611.     time_t    Start;
  1612.     time_t    Future;
  1613. {
  1614.     time_t    StartDay;
  1615.     time_t    FutureDay;
  1616.  
  1617.     StartDay = (localtime(&Start)->tm_hour + 1) % 24;
  1618.     FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
  1619.     return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
  1620. }
  1621.  
  1622.  
  1623. static time_t
  1624. RelativeDate(Start, DayOrdinal, DayNumber)
  1625.     time_t    Start;
  1626.     time_t    DayOrdinal;
  1627.     time_t    DayNumber;
  1628. {
  1629.     struct tm    *tm;
  1630.     time_t    now;
  1631.  
  1632.     now = Start;
  1633.     tm = localtime(&now);
  1634.     now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7);
  1635.     now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
  1636.     return DSTcorrect(Start, now);
  1637. }
  1638.  
  1639.  
  1640. static time_t
  1641. RelativeMonth(Start, RelMonth)
  1642.     time_t    Start;
  1643.     time_t    RelMonth;
  1644. {
  1645.     struct tm    *tm;
  1646.     time_t    Month;
  1647.     time_t    Year;
  1648.  
  1649.     if (RelMonth == 0)
  1650.     return 0;
  1651.     tm = localtime(&Start);
  1652.     Month = 12 * tm->tm_year + tm->tm_mon + RelMonth;
  1653.     Year = Month / 12;
  1654.     Month = Month % 12 + 1;
  1655.     return DSTcorrect(Start,
  1656.         Convert(Month, (time_t)tm->tm_mday, Year,
  1657.         (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
  1658.         MER24, DSTmaybe));
  1659. }
  1660.  
  1661.  
  1662. static int
  1663. LookupWord(buff)
  1664.     char        *buff;
  1665. {
  1666.     register char    *p;
  1667.     register char    *q;
  1668.     register const TABLE    *tp;
  1669.     int            i;
  1670.     int            abbrev;
  1671.  
  1672.     /* Make it lowercase. */
  1673.     for (p = buff; *p; p++)
  1674.     if (isupper(*p))
  1675.         *p = tolower(*p);
  1676.  
  1677.     if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) {
  1678.     yylval.Meridian = MERam;
  1679.     return tMERIDIAN;
  1680.     }
  1681.     if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) {
  1682.     yylval.Meridian = MERpm;
  1683.     return tMERIDIAN;
  1684.     }
  1685.  
  1686.     /* See if we have an abbreviation for a month. */
  1687.     if (strlen(buff) == 3)
  1688.     abbrev = 1;
  1689.     else if (strlen(buff) == 4 && buff[3] == '.') {
  1690.     abbrev = 1;
  1691.     buff[3] = '\0';
  1692.     }
  1693.     else
  1694.     abbrev = 0;
  1695.  
  1696.     for (tp = MonthDayTable; tp->name; tp++) {
  1697.     if (abbrev) {
  1698.         if (strncmp(buff, tp->name, 3) == 0) {
  1699.         yylval.Number = tp->value;
  1700.         return tp->type;
  1701.         }
  1702.     }
  1703.     else if (strcmp(buff, tp->name) == 0) {
  1704.         yylval.Number = tp->value;
  1705.         return tp->type;
  1706.     }
  1707.     }
  1708.  
  1709.     for (tp = TimezoneTable; tp->name; tp++)
  1710.     if (strcmp(buff, tp->name) == 0) {
  1711.         yylval.Number = tp->value;
  1712.         return tp->type;
  1713.     }
  1714.  
  1715.     if (strcmp(buff, "dst") == 0) 
  1716.     return tDST;
  1717.  
  1718.     for (tp = UnitsTable; tp->name; tp++)
  1719.     if (strcmp(buff, tp->name) == 0) {
  1720.         yylval.Number = tp->value;
  1721.         return tp->type;
  1722.     }
  1723.  
  1724.     /* Strip off any plural and try the units table again. */
  1725.     i = strlen(buff) - 1;
  1726.     if (buff[i] == 's') {
  1727.     buff[i] = '\0';
  1728.     for (tp = UnitsTable; tp->name; tp++)
  1729.         if (strcmp(buff, tp->name) == 0) {
  1730.         yylval.Number = tp->value;
  1731.         return tp->type;
  1732.         }
  1733.     buff[i] = 's';        /* Put back for "this" in OtherTable. */
  1734.     }
  1735.  
  1736.     for (tp = OtherTable; tp->name; tp++)
  1737.     if (strcmp(buff, tp->name) == 0) {
  1738.         yylval.Number = tp->value;
  1739.         return tp->type;
  1740.     }
  1741.  
  1742.     /* Military timezones. */
  1743.     if (buff[1] == '\0' && isalpha(*buff)) {
  1744.     for (tp = MilitaryTable; tp->name; tp++)
  1745.         if (strcmp(buff, tp->name) == 0) {
  1746.         yylval.Number = tp->value;
  1747.         return tp->type;
  1748.         }
  1749.     }
  1750.  
  1751.     /* Drop out any periods and try the timezone table again. */
  1752.     for (i = 0, p = q = buff; *q; q++)
  1753.     if (*q != '.')
  1754.         *p++ = *q;
  1755.     else
  1756.         i++;
  1757.     *p = '\0';
  1758.     if (i)
  1759.     for (tp = TimezoneTable; tp->name; tp++)
  1760.         if (strcmp(buff, tp->name) == 0) {
  1761.         yylval.Number = tp->value;
  1762.         return tp->type;
  1763.         }
  1764.  
  1765.     return tID;
  1766. }
  1767.  
  1768.  
  1769. static int
  1770. yylex()
  1771. {
  1772.     register char    c;
  1773.     register char    *p;
  1774.     char        buff[20];
  1775.     int            Count;
  1776.     int            sign;
  1777.  
  1778.     for ( ; ; ) {
  1779.     while (isspace(*yyInput))
  1780.         yyInput++;
  1781.  
  1782.     if (isdigit(c = *yyInput) || c == '-' || c == '+') {
  1783.         if (c == '-' || c == '+') {
  1784.         sign = c == '-' ? -1 : 1;
  1785.         if (!isdigit(*++yyInput))
  1786.             /* skip the '-' sign */
  1787.             continue;
  1788.         }
  1789.         else
  1790.         sign = 0;
  1791.         for (yylval.Number = 0; isdigit(c = *yyInput++); )
  1792.         yylval.Number = 10 * yylval.Number + c - '0';
  1793.         yyInput--;
  1794.         if (sign < 0)
  1795.         yylval.Number = -yylval.Number;
  1796.         return sign ? tSNUMBER : tUNUMBER;
  1797.     }
  1798.     if (isalpha(c)) {
  1799.         for (p = buff; isalpha(c = *yyInput++) || c == '.'; )
  1800.         if (p < &buff[sizeof buff - 1])
  1801.             *p++ = c;
  1802.         *p = '\0';
  1803.         yyInput--;
  1804.         return LookupWord(buff);
  1805.     }
  1806.     if (c != '(')
  1807.         return *yyInput++;
  1808.     Count = 0;
  1809.     do {
  1810.         c = *yyInput++;
  1811.         if (c == '\0')
  1812.         return c;
  1813.         if (c == '(')
  1814.         Count++;
  1815.         else if (c == ')')
  1816.         Count--;
  1817.     } while (Count > 0);
  1818.     }
  1819. }
  1820.  
  1821.  
  1822. #define TM_YEAR_ORIGIN 1900
  1823.  
  1824. /* Yield A - B, measured in seconds.  */
  1825. static time_t
  1826. difftm(a, b)
  1827.      struct tm *a, *b;
  1828. {
  1829.   int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
  1830.   int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
  1831.   return
  1832.     (
  1833.      (
  1834.       (
  1835.        /* difference in day of year */
  1836.        a->tm_yday - b->tm_yday
  1837.        /* + intervening leap days */
  1838.        +  ((ay >> 2) - (by >> 2))
  1839.        -  (ay/100 - by/100)
  1840.        +  ((ay/100 >> 2) - (by/100 >> 2))
  1841.        /* + difference in years * 365 */
  1842.        +  (time_t)(ay-by) * 365
  1843.        )*24 + (a->tm_hour - b->tm_hour)
  1844.       )*60 + (a->tm_min - b->tm_min)
  1845.      )*60 + (a->tm_sec - b->tm_sec);
  1846. }
  1847.  
  1848. time_t
  1849. get_date(p, now)
  1850.     char        *p;
  1851.     struct timeb    *now;
  1852. {
  1853.     struct tm        *tm, gmt;
  1854.     struct timeb    ftz;
  1855.     time_t        Start;
  1856.     time_t        tod;
  1857.  
  1858.     yyInput = p;
  1859.     if (now == NULL) {
  1860.         now = &ftz;
  1861.     (void)time(&ftz.time);
  1862.  
  1863.     if (! (tm = gmtime (&ftz.time)))
  1864.         return -1;
  1865.     gmt = *tm;    /* Make a copy, in case localtime modifies *tm.  */
  1866.     ftz.timezone = (long) difftm (&gmt, localtime (&ftz.time)) / 60;
  1867.     }
  1868.  
  1869.     tm = localtime(&now->time);
  1870.     yyYear = tm->tm_year;
  1871.     yyMonth = tm->tm_mon + 1;
  1872.     yyDay = tm->tm_mday;
  1873.     yyTimezone = now->timezone;
  1874.     yyDSTmode = DSTmaybe;
  1875.     yyHour = 0;
  1876.     yyMinutes = 0;
  1877.     yySeconds = 0;
  1878.     yyMeridian = MER24;
  1879.     yyRelSeconds = 0;
  1880.     yyRelMonth = 0;
  1881.     yyHaveDate = 0;
  1882.     yyHaveDay = 0;
  1883.     yyHaveRel = 0;
  1884.     yyHaveTime = 0;
  1885.     yyHaveZone = 0;
  1886.  
  1887.     if (yyparse()
  1888.      || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
  1889.     return -1;
  1890.  
  1891.     if (yyHaveDate || yyHaveTime || yyHaveDay) {
  1892.     Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
  1893.             yyMeridian, yyDSTmode);
  1894.     if (Start < 0)
  1895.         return -1;
  1896.     }
  1897.     else {
  1898.     Start = now->time;
  1899.     if (!yyHaveRel)
  1900.         Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) + tm->tm_sec;
  1901.     }
  1902.  
  1903.     Start += yyRelSeconds;
  1904.     Start += RelativeMonth(Start, yyRelMonth);
  1905.  
  1906.     if (yyHaveDay && !yyHaveDate) {
  1907.     tod = RelativeDate(Start, yyDayOrdinal, yyDayNumber);
  1908.     Start += tod;
  1909.     }
  1910.  
  1911.     /* Have to do *something* with a legitimate -1 so it's distinguishable
  1912.      * from the error return value.  (Alternately could set errno on error.) */
  1913.     return Start == -1 ? 0 : Start;
  1914. }
  1915.  
  1916.  
  1917. #if    defined(TEST)
  1918.  
  1919. /* ARGSUSED */
  1920. main(ac, av)
  1921.     int        ac;
  1922.     char    *av[];
  1923. {
  1924.     char    buff[128];
  1925.     time_t    d;
  1926.  
  1927.     (void)printf("Enter date, or blank line to exit.\n\t> ");
  1928.     (void)fflush(stdout);
  1929.     while (gets(buff) && buff[0]) {
  1930.     d = get_date(buff, (struct timeb *)NULL);
  1931.     if (d == -1)
  1932.         (void)printf("Bad format - couldn't convert.\n");
  1933.     else
  1934.         (void)printf("%s", ctime(&d));
  1935.     (void)printf("\t> ");
  1936.     (void)fflush(stdout);
  1937.     }
  1938.     exit(0);
  1939.     /* NOTREACHED */
  1940. }
  1941. #endif    /* defined(TEST) */
  1942.